package com.intel.two.controller.information;

import com.intel.two.common.LayuiPageVo;
import com.intel.two.common.R;
import com.intel.two.pojo.information.Lost;
import com.intel.two.service.information.LostService;
import com.intel.two.utils.OssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import java.util.Map;

@RestController
@RequestMapping("/lost")
public class LostController {
    @Autowired
    private LostService lostService;

    /*查全部+分页*/
    @RequestMapping("/lostList")
    public LayuiPageVo<Lost> lostPageData(@RequestParam Map<String, Object> params) {
        System.out.println(params);
        return lostService.lostPageData(params);
    }

    /*增加*/
    @PostMapping("/addLost")
    public R addLost(Lost lost) {
        System.out.println(lost);
        int result = lostService.addLost(lost);
        if (result == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }
    @PostMapping("/uploadPic")
    public R uploadPic(MultipartFile file) throws Exception {
        String originalFilename = file.getOriginalFilename();
        String fileUrl = OssUtil.updateLoad(file.getInputStream(), originalFilename);
        return R.ok().data("url",fileUrl);
    }



    @GetMapping("/deleteLost")
    public R deleteLost(Integer lost_id) {
        int result = lostService.deleteLost(lost_id);
        if (result == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @GetMapping("/deleteLostAll")
    public R deleteLostAll(@RequestParam Map<String, Object> map) {
        int result = lostService.deleteLostAll(map);
        if (result > 0) {
            return R.ok();
        } else {
            return R.error();
        }
    }
    @PostMapping("updateLost")
    public R updateLost(Lost lost) {
        System.out.println(lost);
        int result = lostService.updateLost(lost);
        if (result == 1) {
            return R.ok();
        } else {
            return R.error();
        }
    }


}